//
//  RCDefaultCenterView.m
//  RCsinaMicroBlog
//
//  Created by Mr.Ray on 15/2/3.
//  Copyright (c) 2015年 Ray.peng. All rights reserved.
//

#import "RCDefaultCenterView.h"
@interface RCDefaultCenterView ()
/**
 *  图标
 */
@property (weak, nonatomic) IBOutlet UIImageView *icon;
/**
 *  描述
 */
@property (weak, nonatomic) IBOutlet UILabel *descriptionLb;

/**
 *  定时器
 */
@property (nonatomic, strong) CADisplayLink *link;


/**
 *  登陆按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
/**
 *  注册按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *registerBtn;
/**
 *  点击登陆按钮
 */
- (IBAction)loginBtnOnClick:(UIButton *)sender;
/**
 *  点击注册按钮
 */
- (IBAction)registerBtnOnClick:(UIButton *)sender;


@end

@implementation RCDefaultCenterView

+ (instancetype)defaultCenter{
    return [[[NSBundle mainBundle] loadNibNamed:@"RCDefaultCenterView" owner:nil options:nil] lastObject];
}

- (void)setIconImageName:(NSString *)iconImageName{
    self.icon.image = [UIImage imageNamed:iconImageName];
}

- (void)setInfo:(NSString *)info{
    self.descriptionLb.text = info;
}

- (IBAction)loginBtnOnClick:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(defauletCenterView:didClickLoginBtn:)]) {
        [self.delegate defauletCenterView:self didClickLoginBtn:sender];
    }
}
- (IBAction)registerBtnOnClick:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(defauletCenterView:didClickRegisterBtn:)]) {
        [self.delegate defauletCenterView:self didClickRegisterBtn:sender];
    }
}


/**
 *  懒加载定时器
 */
- (CADisplayLink *)link{
    if (!_link) {
        _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
    }
    return _link;
}

- (void)startRotate{
    [self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}

- (void)stopRotate{
    [self.link invalidate];
    self.link = nil;
    
}
- (void)update{
    self.turntableIv.transform = CGAffineTransformRotate(self.turntableIv.transform, M_PI/200);
}

@end
